perm filename MAN3.TEX[TEX,ALS] blob sn#601460 filedate 1981-07-30 generic text, type C, neo UTF8
COMMENT ⊗   VALID 00003 PAGES
C REC  PAGE   DESCRIPTION
C00001 00001
C00002 00002	\input manhdr[tex,dek]  % This is the TEX user manual source text
C00004 00003	\specialchapterbegin 22. {Alignment}
C00014 ENDMK
C⊗;
\input manhdr[tex,dek]  % This is the TEX user manual source text
\titlepage
\tenpoint
\null\vskip-46pt
\hbox to size{\:<Stanford Artificial Intelligence Laboratory\hfill September
1979}
\hbox to size{\:<Memo AIM-317.3\hfill(fourth printing)}
\vskip .25in
\hbox{\:<Computer Science Department}
\hbox{\:<Report No. STAN-CS-78-675}
\eject\titlepage
\specialchapterbegin 22. {Alignment}
A novice \TEX\ user can prepare manuscripts that involve mathematical
formulas but no complicated tables; but a \TEX\ Master can prepare complicated
tables using {\≡\halign≡\} or {\≡\valign≡\}. In this chapter, if you're
ready for it, you can learn to be a \TEX\ Master.\xskip
(And the next chapter---which
talks about the design of {\≡\output≡\} routines---will enable you to
become a Grandmaster.)

\danger For simplicity, let's consider {\≡\halign≡\} first; {\≡\valign≡\} is
similar, and it is used much more rarely. If you type
$$\hbox{{\≡\halign to ≡\}$\langle$dimen$\rangle${\≡{≡\}$\langle$alignment
preamble$\rangle${\≡\cr≡\}$\langle$alignment entries$\rangle${\≡}≡\}}$$
in vertical mode or restricted vertical mode, you append a list of aligned
boxes that are each $\langle$dimen$\rangle$ units wide to the current
vertical list; these boxes are formed from the $\langle$alignment entries$\rangle$
by using the specifications in the $\langle$alignment preamble$\rangle$. We've
already seen examples of alignment in Chapter 18, where {\≡\halign≡\} was
used to construct matrices. In general, the preamble tells how to format individual
vertical columns whose entries are going to be assembled into horizontal rows of the
specified width. Before we get into any details of the alignment, let's
observe straightaway that ``{\≡\halign to ≡\}$\langle$dimen$\rangle$''
can be changed to ``{\≡\halign to size≡\}'' if the $\langle$dimen$\rangle$
 is to be the current
{\≡\hsize≡\}; it can be shortened to simply ``{\≡\halign≡\}'' if the minimum
size (without shrinking) is desired, or replaced by ``{\≡\halign expand
≡\}$\langle$dimen$\rangle$'' if the boxes should be stretched to a given amount
in addition to this minimum size. In other words, {\≡\halign≡\} has the same
four options as {\≡\hbox≡\}.

\danger The $\langle$alignment preamble$\rangle$ consists of one or more
$\langle$format$\rangle$ specifications separated by {\≡⊗≡\}'s. Each $\langle
$format$\rangle$ specification is a sequence of tokens that is properly nested
with respect to {\≡{...}≡\} groups and contains exactly one ``{\≡#≡\}''.
For example, the $\langle$alignment preamble$\rangle$ suggested for three-column
matrices in Chapter 18 was
$$\hbox{\≡$\ctr{#}$\quad⊗$\ctr{#}$\quad⊗$\ctr{#}$≡\}\quad.$$
A $\langle$format$\rangle$ is essentially a simple {\≡\def≡\} with one parameter;
the idea is to replace the {\≡#≡\} by whatever alignment entry is typed in
that column position. For example, if the $\langle$alignment entries$\rangle$
following this preamble are
$$\hbox{\≡x≡↓1⊗x≡↓2⊗x≡↓3\cr y≡↓1⊗y≡↓2⊗y≡↓3\cr≡\}$$
then there will be two rows of the matrix obtained by substituting these entries
in the preamble, namely
$$\vcenter{\halign{#\cr
{\≡$\ctr{x≡↓1}$\quad≡ ≡ ≡ ≡ ≡ $\ctr{x≡↓2}$\quad≡ ≡ ≡ ≡ ≡ $\ctr{x≡↓3}$≡\}\cr
{\≡$\ctr{y≡↓1}$\quad≡ ≡ ≡ ≡ ≡ $\ctr{y≡↓2}$\quad≡ ≡ ≡ ≡ ≡ $\ctr{y≡↓3}$≡\}\cr}}$$
The $\langle$alignment entries$\rangle$ consist of zero or more $\langle$row$
\rangle$s; and a $\langle$row$\rangle$ is one or more entries separated by
{\≡⊗≡\}'s and followed by {\≡\cr≡\}. In general if the preamble contains $n$
$\langle$format$\rangle$s
$$\tabskip 0pt plus 10000000000pt
\halign to size{\ctr{$# $}\tabskip 0pt⊗#⊗\ctr{$# $}⊗#⊗\ctr{$#
$}⊗#⊗\ctr{$# $}⊗#\hfill\tabskip 0pt plus 10000000000pt\cr
\langle u↓1\rangle\hbox{\tt\char'43}\langle v↓1\rangle⊗{\≡⊗≡\}⊗
\langle u↓2\rangle\hbox{\tt\char'43}\langle v↓2\rangle⊗{\≡⊗≡\}⊗\;\;\cdots\;\;
⊗{\≡⊗≡\}⊗\langle u↓n\rangle\hbox{\tt\char'43}\langle v↓n\rangle\cr
\noalign{\vskip 11pt plus 3pt minus 8pt
\hbox{and if there are $m$ rows each containing $n$ entries}
\vskip 11pt plus 3pt minus 8pt}
\langle x↓{11}\rangle⊗{\≡⊗≡\}⊗\langle x↓{12}\rangle⊗{\≡⊗≡\}⊗
\cdots⊗{\≡⊗≡\}⊗\langle x↓{1n}\rangle⊗{\≡\cr≡\}\cr
\noalign{\penalty 1000}
\langle x↓{21}\rangle⊗{\≡⊗≡\}⊗\langle x↓{22}\rangle⊗{\≡⊗≡\}⊗
\cdots⊗{\≡⊗≡\}⊗\langle x↓{2n}\rangle⊗{\≡\cr≡\}\cr
\noalign{\penalty 1000}
\vdots⊗⊗\vdots⊗⊗⊗⊗\vdots\cr
\noalign{\penalty 1000}
\langle x↓{m1}\rangle⊗{\≡⊗≡\}⊗\langle x↓{m2}\rangle⊗{\≡⊗≡\}⊗
\cdots⊗{\≡⊗≡\}⊗\langle x↓{mn}\rangle⊗{\≡\cr≡\}\cr
\noalign{\vskip 11pt plus 3pt minus 8pt
\hbox{we will obtain $mn$ fleshed-out entries}
\vskip 11pt plus 3pt minus 8pt}
\langle u↓1\rangle\langle x↓{11}\rangle\langle v↓1\rangle⊗⊗
\langle u↓2\rangle\langle x↓{12}\rangle\langle v↓2\rangle⊗⊗\cdots⊗⊗
\langle u↓n\rangle\langle x↓{1n}\rangle\langle v↓n\rangle\cr
\noalign{\penalty 1000}
\langle u↓1\rangle\langle x↓{21}\rangle\langle v↓1\rangle⊗⊗
\langle u↓2\rangle\langle x↓{22}\rangle\langle v↓2\rangle⊗⊗\cdots⊗⊗
\langle u↓n\rangle\langle x↓{2n}\rangle\langle v↓n\rangle\cr
\noalign{\penalty 1000}
\vdots⊗⊗\vdots⊗⊗⊗⊗\vdots\cr
\noalign{\penalty 1000}
\langle u↓1\rangle\langle x↓{m1}\rangle\langle v↓1\rangle⊗⊗
\langle u↓2\rangle\langle x↓{m2}\rangle\langle v↓2\rangle⊗⊗\cdots⊗⊗
\langle u↓n\rangle\langle x↓{mn}\rangle\langle v↓n\rangle\cr}$$
by repeatedly copying the preamble format information.

\danger Now here's what \TEX\ does with the $mn$ fleshed-out entries: The
natural width of each entry {\≡\hbox{≡\}$\langle u↓j\rangle\langle x↓{ij}
\rangle\langle v↓j\rangle${\≡}≡\} is determined; and the {\sl maximum}
natural width is computed in each column. Suppose that $w↓j$ is the maximum natural
width in the $j$th column; then each fleshed-out entry in that column
is replaced by the
box ``{\≡\hbox to ≡\}$w↓j${\≡{≡\}$\langle u↓j\rangle\langle x↓{ij}
\rangle\langle v↓j\rangle${\≡}≡\}''. Thus, all entries in a particular column
now have the same width. Finally these boxes are welded together to make the
$m$ rows, by inserting $n+1$ elements of glue in each row (before the first
box, between boxes, and after the last box). The glue to use in this welding
process has previously been specified by ``{\≡\tabskip≡\}$\langle$glue$\rangle$''.
The $m$ row boxes are finally appended to the current vertical list.

\par\vfill\end